<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="预约名称" prop="subscribeName">
        <el-input v-model="queryParams.subscribeName" placeholder="请输入预约名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="类别名称" prop="personId">
        <el-input v-model="queryParams.personId" placeholder="请输入类别名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="类别名称" prop="personId">
        <el-select v-model="queryParams.personId" placeholder="请输入类别名称" clearable>
          <el-option v-for="dict in dict.type.person_id" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="预约时间" prop="subscribeTime">
        <el-date-picker clearable v-model="queryParams.subscribeTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择预约时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预约状态" prop="sType">
        <el-select v-model="queryParams.sType" placeholder="请选择预约状态" clearable>
          <el-option v-for="dict in dict.type.s_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:subscribe:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:subscribe:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:subscribe:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:subscribe:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="subscribeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="预约名称" align="center" prop="subscribeName" />
      <el-table-column label="类别名称" align="center" prop="personId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.person_id" :value="scope.row.personId" />
        </template>
      </el-table-column>
      <el-table-column label="预约内容" :show-overflow-tooltip="true" align="center" prop="subscribeContent" />
      <el-table-column label="预约时间" align="center" prop="subscribeTime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.subscribeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="sType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.s_type" :value="scope.row.sType" />
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="subscribeChuliren">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.company_shouliname" :value="scope.row.subscribeChuliren" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="预约手机号" :show-overflow-tooltip="true" align="center" prop="subscribePhone" /> -->
      <el-table-column prop="subscribePhone" label="预约手机号" align="center">
        <template slot-scope="scope">
          {{ scope.row.subscribePhone ? scope.row.subscribePhone.replace(/(\d{3})(\d{4})(\d{4})/, "$1****$3") : "" }}
        </template>
      </el-table-column>

      
      <el-table-column prop="subscribeShenfen" label="身份证" align="center">
        <template slot-scope="scope">
          {{ scope.row.subscribeShenfen ? scope.row.subscribeShenfen.replace(/(\d{3})(\d{4})(\d{4})/, "$1***********$3") : "" }}
        </template>
      </el-table-column>

      
      
      
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:subscribe:edit']">处理</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:subscribe:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改预约服务管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="预约回复" prop="subscribeText">
          <el-input v-model="form.subscribeText"  :rows="7" style="font-size: 20px;" type="textarea" placeholder="请输入接收or婉拒的消息喵i~" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1" style="color:yellowgreen;">接收该预约</el-button>
        <el-button type="primary" @click="submitForm2" style="color: red;">婉拒该预约</el-button>

        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSubscribe, getSubscribe, delSubscribe, addSubscribe, updateSubscribe } from "@/api/system/subscribe";

export default {
  name: "Subscribe",
  dicts: ['company_shouliname', 's_type','person_id'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约服务管理表格数据
      subscribeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        subscribeName: null,
        personId: null,
        subscribeContent: null,
        subscribeTime: null,
        sType: null,
        subscribeText: null,
        subscribeChuliren: null,
        subscribePhone: null,
        subscribeShenfen: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        subscribeText:  { required: true, message: "内容不能为空", trigger: "blur" },
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预约服务管理列表 */
    getList() {
      this.loading = true;
      listSubscribe(this.queryParams).then(response => {
        this.subscribeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        subscribeId: null,
        subscribeName: null,
        personId: null,
        subscribeContent: null,
        subscribeTime: null,
        sType: null,
        subscribeText: null,
        subscribeChuliren: null,
        subscribePhone: null,
        subscribeShenfen: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.subscribeId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约服务管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if(row.sType==0||row.sType==2){
        this.$modal.msgSuccess("已经处理过该预约哦~~~~~");

      }else{
        this.reset();
      const subscribeId = row.subscribeId || this.ids
      getSubscribe(subscribeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "处理预约服务管理";
      });
      }

    },
    /** 提交按钮 */
    submitForm1() {
      this.form.sType = 0;
this.form . subscribeText = null,

      this.$refs["form"].validate(valid => {
          if (this.form.subscribeId != null) {
            updateSubscribe(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
      });
    },
    submitForm2() {
      this.form.sType = 2;
      this.form . subscribeText = null,

      this.$refs["form"].validate(valid => {
          if (this.form.subscribeId != null) {
            updateSubscribe(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const subscribeIds = row.subscribeId || this.ids;
      this.$modal.confirm('是否确认删除预约服务管理编号为"' + subscribeIds + '"的数据项？').then(function () {
        return delSubscribe(subscribeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/subscribe/export', {
        ...this.queryParams
      }, `subscribe_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
